000100******************************************************************
000200*PROGRAM : Build zip ISAM                                        *
000300*AUTHOR  : Minh-Tuan Ta                                          *
000400*DATE    : 02/13/12                                              *
000500*ABSTRACT: Build ZIP ISAM file                                   *
000600******************************************************************
000700 IDENTIFICATION DIVISION.
000800 PROGRAM-ID. BUILD-ZIP-ISAM.
000900 ENVIRONMENT DIVISION.
001000     SELECT INFILE       ASSIGN TO "ZIPFILE.TXT"
001100                         ORGANIZATION IS LINE SEQUENTIAL.
001200
001300     SELECT SRTWRK       ASSIGN TO "SRTFILE.WRK".
001400
001500     SELECT OUTFILE      ASSIGN TO "ZIPFILE.DAT"
001600                         ORGANIZATION  IS INDEXED
001700                         ACCESS        IS SEQUENTIAL
001800                         RECORD KEY    IS OUT-ZIP
001900                         ALTERNATE KEY IS OUT-CITY WITH
002000                                          DUPLICATES
002100                         FILE STATUS   IS WS-STAT.
002200
002300 DATA DIVISION.
002400 FILE SECTION.
002500 FD  INFILE.
002600 01  IN-REC.
002700     03  IN-ZIP      PIC X(5).
002800     03  IN-CITY     PIC X(30).
002900     03  IN-STATE    PIC X(2).
003000     03  IN-COUNTY   PIC X(30).
003100
003200 SD  SRTWRK.
003300 01  SRT-REC.
003400     03  SRT-KEY     PIC X(5).
003500     03  SRT-REST    PIC X(62).
003600
003700 FD  OUTFILE.
003800 01  OUT-REC.
003900     03  OUT-ZIP     PIC X(5).
004000     03  OUT-CITY    PIC X(30).
004100     03  OUT-STATE   PIC X(2).
004200     03  OUT-COUNTY  PIC X(30).
004300
004400 WORKING-STORAGE SECTION.
004500 01  WS-STAT         PIC XX.
004600 01  WS-EOF          PIC X VALUE 'N'.
004700 SCREEN SECTION.
004800 01  BUILDING-SCRN.
004900     03  BLANK SCREEN.
005000     03  LINE 12 COL 32 VALUE "BUILDING ZIP FILE".
005100 01  ERROR-SCRN.
005200     03  BLANK SCREEN.
005300     03  LINE 12 COL 32 VALUE "ERROR BUILDING FILE".
005400     03  LINE 14 COL 32 VALUE "FILE STATUS:".
005500     03          COL 46 PIC XX FROM WS-STAT.
005600     03  LINE 15 COL 32 VALUE "RECORD KEY:".
005700     03          COL 46 PIC X(5) FROM SRT-KEY.
005800     03  LINE 19 COL 32 VALUE "PROGRAM TERMINATED".
005900
006000
006100 PROCEDURE DIVISION.
006200 100-MAIN.
006300     OPEN OUTPUT OUTFILE.
006400     DISPLAY BUILDING-SCRN
006500     SORT SRTWRK ON ASCENDING KEY SRT-KEY
006600                 USING INFILE
006700                 OUTPUT PROCEDURE 200-CREATE-OUTPUT.
006800     CLOSE OUTFILE.
006900     EXIT PROGRAM.
007000
007100 200-CREATE-OUTPUT.
007200     RETURN SRTWRK AT END MOVE 'Y' TO WS-EOF.
007300     PERFORM 300-LOOP UNTIL WS-EOF = 'Y'.
007400
007500 300-LOOP.
007600     MOVE SRT-REC TO OUT-REC.
007700     WRITE OUT-REC
007800         INVALID KEY DISPLAY ERROR-SCRN
007900         STOP RUN
008000     END-WRITE
008100     RETURN SRTWRK AT END MOVE 'Y' TO WS-EOF.
008200
